package main

import (
	"ruanGongKeShe16Zu/controller"
	"ruanGongKeShe16Zu/middleware"

	"github.com/gin-gonic/gin"
)

func RouteList(r *gin.Engine) *gin.Engine {
	//允许跨域
	r.Use(middleware.CORSMiddleware(), middleware.RecoveryMiddleware())

	userRoute := r.Group("/user")
	userRoute.POST("register", controller.Register)
	userRoute.POST("login", controller.Login)
	userRoute.GET("info", middleware.AuthMiddleware(), controller.Info)

	categoryRoute := r.Group("/category")
	categoryController := controller.NewCategoryController()
	categoryRoute.POST("create", categoryController.Create)
	categoryRoute.GET("/:id", categoryController.Retrieve)
	categoryRoute.PUT("/:id", categoryController.Update)
	categoryRoute.DELETE("/:id", categoryController.Delete)
	categoryRoute.POST("list", categoryController.ListCategory)

	instrumentRoute := r.Group("/instrument")
	instrumentController := controller.NewInstrumentController()
	instrumentRoute.POST("create", instrumentController.Create)
	instrumentRoute.GET("/:id", instrumentController.Retrieve)
	instrumentRoute.PUT("/:id", instrumentController.Update)
	instrumentRoute.DELETE("/:id", instrumentController.Delete)
	instrumentRoute.POST("list", instrumentController.ListInstrument)

	orderRoute := r.Group("/order")
	// orderRoute.Use(middleware.AuthMiddleware())
	orderController := controller.NewOrderController()
	orderRoute.POST("create", orderController.Create)
	orderRoute.GET("/:id", orderController.Retrieve)
	orderRoute.PUT("/:id", orderController.Update)
	orderRoute.DELETE("/:id", orderController.Delete)
	orderRoute.POST("list", orderController.ListOrder)
	orderRoute.POST("user/:id", orderController.SelectByUserID)

	cartRoute := r.Group("/cart")
	// cartRoute.Use(middleware.AuthMiddleware())
	cartController := controller.NewCartController()
	cartRoute.POST("create", cartController.Create)
	cartRoute.GET("/:id", cartController.Retrieve)
	cartRoute.PUT("/:id", cartController.Update)
	cartRoute.DELETE("/:id", cartController.Delete)
	cartRoute.POST("list", cartController.ListCart)
	cartRoute.POST("user/:id", cartController.SelectByUserID)
	cartRoute.DELETE("user/:id", cartController.DeleteByUserID)

	commentRoute := r.Group("/comment")
	// cartRoute.Use(middleware.AuthMiddleware())
	commentController := controller.NewCommentController()
	commentRoute.POST("create", commentController.Create)
	commentRoute.GET("/:id", commentController.Retrieve)
	commentRoute.PUT("/:id", commentController.Update)
	commentRoute.DELETE("/:id", commentController.Delete)
	commentRoute.POST("list", commentController.ListComment)
	commentRoute.POST("instrument/:id", commentController.SelectByInstrumentID)
	return r
}
